/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server.closeClientConnections;

import java.net.ServerSocket;
import java.util.Collection;
import server.server.senderEvent.SenderProducer;
import java.util.HashMap;

/**
 *
 * @author Александр Емельянов (mr.lex91@gmail.com)
 */
public class CloseClientConnectionsProducer {
    private HashMap<String, CloseClientConnectionsListener> list= new HashMap<String, CloseClientConnectionsListener>();
    public void addClientConnectionsListener(CloseClientConnectionsListener listener)
    {
        list.put(listener.getNickName(), listener);
    }
    public CloseClientConnectionsListener[] getCloseClientConnectionsListener()
    {
        return (CloseClientConnectionsListener[]) list.values().toArray();
    }

    public void removeCloseClientConnectionsListener(String nickName)
    {
        list.remove(nickName);
    }

    private void fire(String msg)
    {
        CloseClientConnectionsEvent ev = new CloseClientConnectionsEvent(this,msg);
            while (!list.isEmpty()) for(CloseClientConnectionsListener listener: list.values())
            {
                listener.CloseClientConnections(ev);
                break;
            }
    }
    private void fire(String msg, String nickName)
    {
        CloseClientConnectionsEvent ev = new CloseClientConnectionsEvent(this,msg);
            if (list.containsKey(nickName)) list.get(nickName).CloseClientConnections(ev);
    }
    public void CloseClientConnections()
    {
        fire("Close");
    }
    public void LogOut()
    {
        fire("LogOut");
    }
    public void CloseClientConnections(String nickName)
    {
        fire("Close",nickName);
    }
    public void LogOut(String nickName)
    {
        fire("LogOut",nickName);
    }
}
